package com.deyuanyun.pic.insp.controller.inspresult;

import com.deyuanyun.pic.common.util.RequestUtil;
import com.deyuanyun.pic.common.util.ResponseUtil;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.insp.util.InspExportUtil;
import com.deyuanyun.pic.settings.controller.AbstractBaseController;
import com.deyuanyun.pic.insp.service.inspresult.InspGwwService;
import com.deyuanyun.pic.settings.support.utils.ExcelUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/insp/gww")
public class InspGwwController extends AbstractBaseController {
	@Resource
	private InspGwwService inspgwwservice;

	@RequestMapping("/searchgww")
	public void searchMaintainability(@RequestParam HashMap<String, Object> map, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView();
		int pageCount = 10;

		if (null != map.get("pageSize")) {
			pageCount = Integer.valueOf(map.get("pageSize").toString());
		}
		int current = 1;
		if (null != map.get("pageNo")) {
			current = Integer.valueOf(map.get("pageNo").toString());
		}
		PageHelper.startPage(current, pageCount);
		// 条件查询 分页列表
		Page main = inspgwwservice.getMain(map);
		ResponseUtil.printl(response, ResponseUtil.getJson(main).toString(), "JSON");
	}

	@RequestMapping(value="/{id}")
	public ModelAndView getMaintainability(@PathVariable String id) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("tag", id);
		//查询管道名称 
		List lineList=lineService.getLine();
		mv.addObject("lineList", lineList);
		mv.setViewName("insp/statistics/gww");
		return mv;
	}

	@ResponseBody
	@RequestMapping("/export.json")
	public void export(HttpServletRequest request, HttpServletResponse response)
	{


		HashMap param= RequestUtil.parseRequestParamToHashMap(request);
		List result=inspgwwservice.queryExport(param);
		param.put("data",result);
		try {
			InspExportUtil.exportExcel(request.getRealPath("/")+"/WEB-INF/classes/template/excl/insp/gww.xlsx",param,response,"环焊缝");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	@ResponseBody
	@RequestMapping("/exportAll.json")
	public void exportAll(HttpServletRequest request, HttpServletResponse response)
	{


		HashMap param= RequestUtil.parseRequestParamToHashMap(request);
		List result=inspgwwservice.exportAll(param);
		param.put("data",result);
		try {
			InspExportUtil.exportExcel(request.getRealPath("/")+"/WEB-INF/classes/template/excl/insp/all.xlsx",param,response,"特征数据");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@ResponseBody
	@RequestMapping("/exportAllCount.json")
	public void exportAllCount(HttpServletRequest request, HttpServletResponse response)
	{


		HashMap param= RequestUtil.parseRequestParamToHashMap(request);
		Long count=inspgwwservice.exportAllCount(param);
		AjaxSupport.sendSuccessText("msg",count);
	}

}
